package com.charles.video.common.core.responseDomain;

import java.io.Serializable;

public class R<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final int SUCCESS = 200;

    public static final int FAIL = 500;

    private int code;

    private String msg;

    private T data;

    public static <T> R<T> ok() {
        return result(null, SUCCESS, null);
    }

    public static <T> R<T> ok(T data) {
        return result(data, SUCCESS, null);
    }

    public static <T> R<T> ok(T data, String msg) {
        return result(data, SUCCESS, msg);
    }

    public static <T> R<T> fail() {
        return result(null, FAIL, null);
    }

    public static <T> R<T> fail(String msg) {
        return result(null, FAIL, msg);
    }

    public static <T> R<T> fail(T data) {
        return result(data, FAIL, null);
    }

    public static <T> R<T> fail(T data, String msg) {
        return result(data, FAIL, msg);
    }

    public static <T> R<T> result(T data, int code, String msg) {
        R<T> result = new R<>();
        result.setData(data);
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public static int getSUCCESS() {
        return SUCCESS;
    }

    public static int getFAIL() {
        return FAIL;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
